package com.bgs.scheduled;

import cn.hutool.core.date.DateUtil;
import com.bgs.pojo.Money;
import com.bgs.service.MoneyService;
import com.bgs.vo.MoneyVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Calendar;
import java.util.Date;

/**
 * @Auther: 梁玉杰
 * @Date: 2022/3/15 13:43
 * @Description: 定时任务 7子表达式 第7个springBoot已经封装了，写6个就可以了
 */
@Component  //交给spring管理
public class ScheduledTask {

    @Autowired
    private MoneyService moneyService;


    /**
     * 每个月的2号，会自动修改工资的确认状态，条件是根据年和月份查询
     */
    @Scheduled(cron = "0 0 0 0 2/1 ?")
    public void task2() {
        MoneyVo mvo = new MoneyVo();
        Calendar c = Calendar.getInstance();
        int month = c.get(Calendar.MONTH)+1;//获取当前月，根据当前月份去修改工资状态
        String mon = month+"月";
        int year = c.get(Calendar.YEAR); //当前年份
        mvo.setTime(year+"年"+month+"月");
        mvo.setPaytype(1);//1 是确认工资
        moneyService.updateBymonth(mvo);
    }

}
